import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

class MyThread implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"\t******* callable come in ");
        TimeUnit.SECONDS.sleep(3);
        return 1024;
    }
}
/**
 * @auther: Alessio
 * @date: 2021/1/18
 * 多线程中，第3种获得多线程的方法
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask<>(new MyThread());
        new Thread(task,"AA").start();
        int result=100;
        while (!task.isDone()){

        }
        System.out.println("the result is:"+task.get());
    }
}
